package com.woniu.elderly.wares.task;

import com.woniu.elderly.wares.mapper.WaresSkuMapper;
import com.woniu.elderly.wares.utils.AddTime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: xuan
 * @Date: 2024/8/910:01
 * @Version: 1.0
 */
@Slf4j
public class UvTask {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private WaresSkuMapper skuMapper;

    @Scheduled(cron = "0 0 1 ? * ? ")//每天凌晨1点执行
    public void task() {
        //每天统计昨天的uv
        String key = "uv-"+ AddTime.getYesterday();
        Long size = redisTemplate.opsForHyperLogLog().size(key);
        log.info("UV:{}+"+AddTime.getYesterday(),size);
        //持久化到数据库
        skuMapper.taskSave(AddTime.getYesterday(),size);
        //清空昨天的uv
        redisTemplate.delete(key);
    }

}
